package online.sixfish.question.controller;

import online.sixfish.question.service.QueProgramService;
import online.sixfish.common.api.ApiResult;
import online.sixfish.common.dto.PageDTO;
import online.sixfish.question.model.entity.QueProgram;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/que")
public class QueProgramController {

    @Resource
    QueProgramService queProgramService;

    @GetMapping("/program/{id}")
    public ApiResult getQueProgramById(@PathVariable Integer id){
        QueProgram queProgram = queProgramService.getById(id);
        queProgram.setInputSampleData("");
        queProgram.setOutputSampleData("");
        return ApiResult.success(queProgram);
    }

    @GetMapping("/program/list")
    public ApiResult listQueProgram(@RequestParam Integer pageNum,
                                    @RequestParam Integer pageSize,
                                    @RequestParam(required = false) Integer difficulty,
                                    @RequestParam(required = false) Integer userQueStatus) {
        PageDTO<QueProgram> list = queProgramService.list(pageNum, pageSize, difficulty, userQueStatus);
        List<QueProgram> data = list.getData();
        if(CollectionUtils.isNotEmpty(data)){
            for (QueProgram queProgram : data) {
                queProgram.setInputSampleData(null);
                queProgram.setOutputSampleData(null);
            }
        }
        return ApiResult.success(list);
    }

}
